package funcs

import (
	"encoding/json"
	"fmt"
	"gitee.com/wanjimao/common-util/dancetiktok/enums/dancetiktokenums"
	"gitee.com/wanjimao/common-util/dancetiktok/struct/dancetiktokstruct"
	"github.com/go-redis/redis"
	"strconv"
)

func GetPetGradeScore(rdsClient *redis.ClusterClient, envServer string, petType int, quality int, grade int) (petLevelScore *dancetiktokstruct.PetLevelScoreDetail, err error) {
	if grade == 0 {
		grade = 1
	}
	rdsKey := fmt.Sprintf(dancetiktokenums.PetLevelScore, envServer, dancetiktokenums.PlatformTikTok, strconv.Itoa(petType), strconv.Itoa(quality))
	res, err := rdsClient.HGet(rdsKey, strconv.Itoa(grade)).Result()
	if nil != err && err != redis.Nil {
		return nil, err
	}
	if res == "" {
		return nil, nil
	}
	err = json.Unmarshal([]byte(res), &petLevelScore)
	if err != nil {
		return nil, err
	}
	return
}
